package cn.tedu.zhwy.cardealer.service.impl;

import cn.tedu.zhwy.cardealer.mapper.VehicleMapper;
import cn.tedu.zhwy.cardealer.pojo.dto.VehicleQuery;
import cn.tedu.zhwy.cardealer.pojo.dto.VehicleSaveParam;
import cn.tedu.zhwy.cardealer.pojo.entity.Vehicle;
import cn.tedu.zhwy.cardealer.pojo.vo.VehicleVO;
import cn.tedu.zhwy.cardealer.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class VehicleServiceImpl implements VehicleService {

    @Autowired
    VehicleMapper vehicleMapper;

    @Override
    public List<VehicleVO> selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆信息:vehicleQuery{}", vehicleQuery);
        List<VehicleVO> list = vehicleMapper.selectVehicle(vehicleQuery);
        return list;
    }

    @Override
    public void saveVehicle(VehicleSaveParam vehicleSaveParam) {
        log.debug("保存车辆信息:vehicleSaveParam{}", vehicleSaveParam);
        Vehicle vehicle=new Vehicle();
        BeanUtils.copyProperties(vehicleSaveParam,vehicle);
        if (vehicle.getCarId()==null){
            vehicleMapper.insert(vehicle);
        }else {
            vehicleMapper.update(vehicle);
        }
    }

    @Override
    public void deleteVehicle(Long carId) {
        log.debug("删除车辆信息:carId{}", carId);
        vehicleMapper.deleteVehicle(carId);
    }
}
